package sketch.generator;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import sketch.util.Checker;

public class LinkCreator {
	
	public static IIterationLink createCombinatoricLink(IGenerator<?>... generators) {
		Checker.checkTrue(generators.length > 0, "There should be more than 0 generators");
		IIterationLink retLink = new GeneratorLink(generators[0]);
		for(int i = 1; i < generators.length; i++) {
			retLink = new CombinatoricLink(retLink, new GeneratorLink(generators[i]));
		}
		return retLink;
	}
	
	public static IIterationLink createInOrderGenCombinatoricLink(IGenerator<?>... generators) {
		Checker.checkTrue(generators.length > 0, "There should be more than 0 generators, length of generators: " + generators.length);
		List<IGenerator<?>> genList = new LinkedList<IGenerator<?>>();
		for(IGenerator<?> gen : generators) {
			genList.add(gen);
		}
		return createInOrderGenCombinatoricLink(genList);
	}
	
	public static IIterationLink createInOrderGenCombinatoricLink(List<IGenerator<?>> generators) {
		Collections.reverse(generators);
		return createReverseOrderGenCombinatoricLink(generators);
	}
	
	public static IIterationLink createReverseOrderGenCombinatoricLink(List<IGenerator<?>> generators) {
		Checker.checkTrue(generators.size() > 0, "There should be more than 0 generators");
		IIterationLink retLink = new GeneratorLink(generators.get(0));
		for(int i = 1; i < generators.size(); i++) {
			retLink = new CombinatoricLink(retLink, new GeneratorLink(generators.get(i)));
		}
		return retLink;
	}
	
	public static IIterationLink createSequentialLink(List<IGenerator<?>> generators) {
		return new SequentialLink(generators);
	}
	
	public static IIterationLink createSequentialLink(IGenerator<?>... generators) {
		List<IGenerator<?>> list = new LinkedList<IGenerator<?>>();
		for(IGenerator<?> generator : generators) {
			list.add(generator);
		}
		return createSequentialLink(list);
	}
}
